﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Spanner;

namespace SpannerWebSite
{
    internal partial class RefArrays : Reference
    {
        internal static SpannerChapter TheChapter;

        static RefArrays()
        {
            var sections = new List<SpannerSection> { };
            var initActs = new List<Act> { };

            Action<string, string, Html> addSection = (title, id, html) =>
            {
                sections.Add(Section(Esc(title), id, html));
            };

            addSection("Note on observable arrays", "Note", P("Observable and computed arrays are handled ",
                "in the same way as ordinary JavaScript arrays: ", Spanner, " automatically manages ",
                "observable dereferencing and so forth."));

            addSection("Array (constructor)", "ArrayConstructor", P(Code("Array(x1, x2, ..., xN)"), " ",
                "denotes the JavaScript array literal ", Code("[x1, x2, ..., xN]"), "."));

            addSection("Array (constructor)", "ArrayConstructor", P(Code("Array(xs)"), " ",
                "denotes the JavaScript array literal obtained from the IEnumerable ", Code("xs"),
                "."));

            addSection("Ith", "Ith", P(Code("Ith(xs, i)"), " denotes the JavaScript ",
                Code("xs[i]"), "."));

            addSection("Concat", "Concat", P(Code("Concat(xs1, xs2, ..., xsN)"), " denotes the JavaScript ",
                Code("[].concat[xs1, xs2, ..., xsN]"), "."));

            addSection("Every", "Every", P(Code("Every(xs, p)"), " denotes the JavaScript ",
                Code("xs.every(p)"), " (this is overloaded to cover all the JavaScript options for ",
                Code("p"), ")."));

            addSection("Filter", "Filter", P(Code("Filter(xs, p)"), " denotes the JavaScript ",
                Code("xs.filter(p)"), " (this is overloaded to cover all the JavaScript options for ",
                Code("p"), ")."));

            addSection("IndexOf", "IndexOf", P(Code("IndexOf(xs, x)"), " denotes the JavaScript ",
                Code("xs.indexOf(x)"), "."));

            addSection("Join", "Join", P(Code("Join(xs [, sep])"), " denotes the JavaScript ",
                Code("xs.join(sep)"), " (the separator parameter is optional)."));

            addSection("LastIndexOf", "LastIndexOf", P(Code("LastIndexOf(xs, x)"), " denotes the JavaScript ",
                Code("xs.lastIndexOf(x)"), "."));

            addSection("Length", "Length", P(Code("Length(xs)"), " denotes the JavaScript ",
                Code("xs.length"), "."));

            addSection("Map", "Map", P(Code("Map(xs, f)"), " denotes the JavaScript ",
                Code("xs.map(f)"), " (this is overloaded to cover all the JavaScript options for ",
                Code("f"), ")."));

            addSection("Pop", "Pop", P(Code("Pop(xs)"), " denotes the JavaScript ",
                Code("xs.pop()"), "."));

            addSection("Shift", "Shift", P(Code("Shift(xs)"), " denotes the JavaScript ",
                Code("xs.shift()"), "."));

            addSection("Reduce", "Reduce", P(Code("Reduce(xs, f, a)"), " denotes the JavaScript ",
                Code("xs.reduce(f, a)"), " (this is overloaded to cover all the JavaScript options for ",
                Code("f"), ")."));

            addSection("ReduceRight", "ReduceRight", P(Code("ReduceRight(xs, f, a)"), " denotes the JavaScript ",
                Code("xs.reduceRight(f, a)"), " (this is overloaded to cover all the JavaScript options for ",
                Code("f"), ")."));

            addSection("Slice", "Slice", P(Code("Slice(xs, begin[, end])"), " denotes the JavaScript ",
                Code("xs.slice(begin, end)"), " (the end parameter is optional)."));

            addSection("Some", "Some", P(Code("Some(xs, p)"), " denotes the JavaScript ",
                Code("xs.some(p)"), " (this is overloaded to cover all the JavaScript options for ",
                Code("p"), ")."));

            addSection("ForEach", "ForEach", P(Code("ForEach(xs, actFn)"), " denotes the JavaScript ",
                Code("xs.ForEach(actFn)"), " (this is overloaded to cover all the JavaScript options for ",
                Code("actFn"), ")."));

            addSection("Push", "Push", P(Code("Push(xs, x)"), " denotes the JavaScript ",
                Code("xs.push(x)"), "."));

            addSection("Reverse", "Reverse", P(Code("Reverse(xs)"), " denotes the JavaScript ",
                Code("xs.reverse()"), "."));

            addSection("Sort", "Sort", P(Code("Sort([cmpFn])"), " denotes the JavaScript ",
                Code("xs.sort(cmpFn)"), " (the comparison function parameter is optional; this is ",
                "overloaded to cover all the JavaScript options for ", Code("cmpFn"), ")."));

            addSection("Splice", "Splice", P(Code("Splice(xs, begin, howMany, ys)"), " denotes the JavaScript ",
                Code("[].splice.apply(xs, [begin, howMany].concat(ys))"), "."));

            addSection("Unshift", "Unshift", P(Code("Unshift(xs, ys)"), " denotes the JavaScript ",
                Code("[].unshift.apply(xs, ys)"), "."));

            TheChapter = CommonUI.Chapter("Reference - Arrays", "RefArrays", sections, initActs);
        }
    }
}
